/*
 * Regola grammaticale
 * <cond> → <termb> [OR <termb>]*
 */
package composite.boolean_expression;

import composite.BooleanExpression;
import composite.Component;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import visitor.Visitor;

/**
 *
 * @author Antonio
 */
public class Cond extends BooleanExpression {
    
    private List<Component> termb;
    
    public Cond(Termb termb) {
        
        this.termb = new LinkedList();
        this.termb.add(termb);
    }
    
    @Override
    public void add(Component termb) {
        
        this.termb.add(termb);
    }// add

    public List<Component> getState() {
        
        return termb;
    }// getState

    @Override
    public void interpreta(String contesto) {
        
        for (Component tb : termb) {
            
            tb.interpreta(contesto);
        }
    }
    
    @Override
    public String toString() {
        
        StringBuilder sb = new StringBuilder();
        Iterator<Component> it = termb.iterator();
        
        sb.append(it.next());
        while (it.hasNext()) {
            
            sb.append(" || ").append(it.next());
            
        }
        return sb.toString();
    }
    
    @Override
    public void accept(Visitor v) {
        
        v.visit(this);
    }
}
